﻿using System.Net;
using System.Net.Http;
using Optum.SN.Infra.Core.Dependency.Service;

namespace Optum.SN.Infra.Core.TestBase.Utility
{
    /// <summary>
    /// Builds <see cref="HttpResponseMessage"/>.
    /// </summary>
    internal sealed class ResponseBuilder
    {
        /// <summary>
        /// Gets/sets the serializer.
        /// </summary>
        internal ISerializer Serializer { private get; set; }
        /// <summary>
        /// Builds <see cref="HttpResponseMessage"/> with status <see cref="HttpStatusCode.OK">OK</see>.
        /// </summary>
        /// <param name="contentRecords">Builds <see cref="HttpResponseMessage"/> content these records.</param>
        /// <returns>Fully hydrated response message.</returns>
        internal HttpResponseMessage BuildGoodRresponse(IEntity contentRecords)
        {
            return BuildResponse(HttpStatusCode.OK, BuildContent(contentRecords));
        }
        /// <summary>
        /// Builds <see cref="HttpResponseMessage"/>.
        /// </summary>
        /// <param name="status">Message status to set.</param>
        /// <param name="content">Message content to set.</param>
        /// <returns>Hydrated response message.</returns>
        private HttpResponseMessage BuildResponse(HttpStatusCode status, HttpContent content)
        {
            return new HttpResponseMessage(status) { Content = content };
        }
        /// <summary>
        /// Builds content for <see cref="HttpResponseMessage"/>.
        /// </summary>
        /// <typeparam name="T">Content record type.</typeparam>
        /// <param name="contentRecords">Content records.</param>
        /// <returns>Hydrated message content.</returns>
        private HttpContent BuildContent<T>(T contentRecords) where T : class
        {
            return new ObjectContent<T>(contentRecords, Serializer.GetFormatter(), Serializer.DataTransferMedia);
        }
    }
}